#include "StdAfx.h"
#include "Playlist.h"


CPlaylist::CPlaylist(void):
	m_CurFileNum(0),
	m_FilesNum(0),
	m_PlayType(BY_ORDER)
{
}


CPlaylist::~CPlaylist(void)
{
}

void CPlaylist::AddToPlaylist(CString FileName)
{
	m_FileList.Add(FileName);
	m_FilesNum++;
}

void CPlaylist::DeletePlaylist(void)
{
	m_FileList.RemoveAll();
	m_FilesNum=0;
	m_CurFileNum=0;
}

int CPlaylist::RemoveFile(int FileNum)
{
	if(FileNum<=m_FilesNum)
	{
		m_FilesNum--;
		m_FileList.RemoveAt(FileNum-1);
		if(FileNum<=m_CurFileNum && m_CurFileNum!=0)
			m_CurFileNum--;
		return m_CurFileNum;
	}
	return 0;
}

CString CPlaylist::SetPlayFile(int FileNum)
{
	if(FileNum<=m_FilesNum)
	{
		m_CurFileNum=FileNum;
		return m_FileList[m_CurFileNum-1];
	}
	return L"";
}

CString CPlaylist::GetNextFile(void)
{
	if(m_FilesNum!=0)
		{
		switch(m_PlayType)
		{
		case BY_ORDER:
			{
				if(m_CurFileNum<m_FilesNum)
					m_CurFileNum++;
				else
					m_CurFileNum=1;
	
				return m_FileList[m_CurFileNum-1];
			}
			break;
		}
	}

	return L"";
}

CString CPlaylist::GetPreviousFile(void)
{
	if(m_FilesNum!=0)
		{
		switch(m_PlayType)
		{
		case BY_ORDER:
			{
				if(m_CurFileNum>1)
					m_CurFileNum--;
				else
					m_CurFileNum=m_FilesNum;
	
				return m_FileList[m_CurFileNum-1];
			}
			break;
		}
	}

	return L"";
}